package com.ruoyi.camp.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

@Component
public class ChatWebSocketHandler extends TextWebSocketHandler {


    private static final Logger log = LoggerFactory.getLogger(ChatWebSocketHandler.class);


    // 连接成功后调用
    @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {

        log.debug("发送uri: " + session.getUri());
        log.debug("参数: " + session.getUri().getQuery());
    }

    @Override
    public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {

        log.debug("handleTextMessage 发送uri: " + session.getUri());
        log.debug("handleTextMessage message: " + message.getPayload());

    }

    @Override
    public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
        log.debug("发送uri: " + session.getUri());
    }

}